package cn.truistic.enmicromsg.common.util;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import cn.truistic.enmicromsg.R;
import cn.truistic.enmicromsg.common.interfaces.DialogCallBack;


/**
 * Created by Teprinciple on 2016/10/13.
 * <p/>
 * 自定义对话框
 */
public class ConfirmDialog extends Dialog implements View.OnClickListener {

    DialogCallBack callback;
    private TextView content;
    private TextView sureBtn;
    private TextView cancleBtn;
    private String contentStr ;
    private Context mContext ; //上下文对象

    public String getContentStr() {
        return contentStr;
    }

    public void setContentStr(String contentStr) {
        this.contentStr = contentStr;
    }

    /**
     * 高仿苹果自定义对话框
     * @param context
     * @param callback
     */
    public ConfirmDialog(Context context, DialogCallBack callback) {
        super(context, R.style.CustomDialog);
        this.mContext = context;
        this.callback = callback;
        setCustomDialog();
    }

    /**
     * 高仿苹果自定义对话框
     *
     * @param context
     */
    public ConfirmDialog(Context context) {
        super(context, R.style.CustomDialog);
        this.mContext = context;
        setCustomDialog();
    }

    private void setCustomDialog() {
        View mView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_confirm, null);
        sureBtn = (TextView) mView.findViewById(R.id.dialog_confirm_sure);
        cancleBtn = (TextView) mView.findViewById(R.id.dialog_confirm_cancle);
        content = (TextView) mView.findViewById(R.id.dialog_confirm_title);
        sureBtn.setOnClickListener(this);
        cancleBtn.setOnClickListener(this);
        if ( null != callback){
            content.setText(contentStr);
        }else{
            content.setText("提示：" + "\n服务没有开启不能进行下一步");
        }
        super.setContentView(mView);
    }


    public ConfirmDialog setContent(String s) {
        content.setText(s);
        return this;
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_confirm_cancle:
                if ( null != callback) {
                    callback.Positive();
                }
                this.cancel();
                break;
            case R.id.dialog_confirm_sure:
                if (null != callback) {
                    callback.Negative();
                }else{
                    mContext.startActivity( new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS) );  //跳转服务界面WxHeple.
                }
                this.cancel();
                break;
        }
    }

}
